package linuxbox.reservation.servlet;

import javax.servlet.http.*;
import java.util.*;
import java.sql.*;

import linuxbox.common.*;
import linuxbox.reservation.logic.*;

public class BoxReservationViewAction extends Action
{
  BoxReservation home = BoxReservation.getInstance();
	protected static String listJSP = null;

  public void doAction(HttpSession session, BoxSession aBoxSession,
            HttpServletRequest req, HttpServletResponse resp) throws Exception
  {
    String str = (String) req.getParameter("VIEW_MINE");
    if ( str != null && str.length() > 0 )
 		  session.setAttribute("resv.VIEW_MINE", str);

    str = (String) req.getParameter("RESOURCEID");
    if ( str != null && str.length() > 0 )
 		  session.setAttribute("resv.RESOURCEID", str);

    str = (String) req.getParameter("RESOURCECATID");
    if ( str != null && str.length() > 0 )
 		  session.setAttribute("resv.RESOURCECATID", str);

    str = (String) req.getParameter("SORTBY");
    if ( str != null && str.length() > 0 )
 		  session.setAttribute("resv.SORTBY", str);

    str = (String) req.getParameter("VIEW_FORMAT");
    if ( str != null && str.length() > 0 )
 		  session.setAttribute("resv.VIEW_FORMAT", str);

    str = (String) req.getParameter("VIEW_TODAY");
    if ( str != null )
    {
  		Calendar currentDate = Calendar.getInstance(aBoxSession.getTimeZone());
 		  session.setAttribute("currentDate", currentDate);

      sendFile(listJSP,req,resp);
      return;
    }

		Calendar currentDate = (Calendar)session.getAttribute("currentDate");
	  if ( currentDate == null )
		{
  		currentDate = Calendar.getInstance(aBoxSession.getTimeZone());
  		session.setAttribute("currentDate", currentDate);
  	}

		str = req.getParameter("t"); //time
		if ( str != null )
		{
			long tmp = Long.parseLong(str);
			currentDate.setTime(new java.sql.Date(tmp));
		}

    str = (String) req.getParameter("ASC");
    if ( str != null && str.length() > 0 )
 		  session.setAttribute("resv.ASC", str);

    //Send BoxReservation.jsp anyway
    sendFile(listJSP, req, resp);
  }
	public void setListJSP(String str)
	{
		listJSP = str;
	}
}
